Skip to content

获取鼠标位置 - GetCursorPos

函数简介

获取鼠标位置。

接口名称

GetCursorPos

DLL调用

int GetCursorPos(long ola, int* x, int* y);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
x整数型指针返回的鼠标X坐标。
y整数型指针返回的鼠标Y坐标。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
string pos = ola.GetCursorPos();
// 返回 "x,y" 格式
csharp
using OLAPlug;

var ola = new OLAPlugServer();
string pos = ola.GetCursorPos();
// 返回 "x,y" 格式
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
pos = ola.GetCursorPos()
# 返回 "x,y" 格式
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
String pos = ola.GetCursorPos();
// 返回 "x,y" 格式
cpp
var ola = com("OlaPlug.OlaSoft")
var pos = ola.GetCursorPos()
// 返回 "x,y" 格式
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
pos = ola.GetCursorPos()
' 返回 "x,y" 格式
text
.局部变量 ola, OLAPlug
ola.创建 ()
pos = ola.GetCursorPos()
' 返回 "x,y" 格式
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var pos = ola.GetCursorPos();
// 返回 "x,y" 格式
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
文本型 pos = ola.GetCursorPos()
// 返回 "x,y" 格式
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
string pos = ola.GetCursorPos();
// 返回 "x,y" 格式

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long posPtr = GetCursorPos(instance);
if (posPtr != 0) {
    char pos[512] = {0};
    GetStringFromPtr(posPtr, pos, sizeof(pos));
    FreeStringPtr(posPtr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long posPtr = GetCursorPos(instance);
if (posPtr != 0) {
    StringBuilder pos = new StringBuilder(GetStringSize(posPtr) + 1);
    GetStringFromPtr(posPtr, pos, pos.Capacity);
    FreeStringPtr(posPtr);
    string posStr = pos.ToString();
}
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
posPtr = GetCursorPos(instance)
if posPtr:
    buf = create_string_buffer(512)
    ola.GetStringFromPtr(posPtr, buf, 512)
    ola.FreeStringPtr(posPtr)
    pos = buf.value.decode("utf-8")

返回值

1 成功,0 失败。

注意事项

  • 此接口绑定后使用,获取的是相对游戏窗口的鼠标坐标。
  • 不受 SetMousePosCallback 影响,始终返回系统/绑定上下文下的实际光标位置。